/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package l2.jw.gameserver.model.actor.instance;

import l2.jw.gameserver.datatables.TeleportLocationTable;
import l2.jw.gameserver.instancemanager.krateiscube.KrateisCubeManager;
import l2.jw.gameserver.model.L2TeleportLocation;
import l2.jw.gameserver.templates.chars.L2NpcTemplate;
import l2.jw.gameserver.network.SystemMessageId;
import java.util.StringTokenizer;

public class L2KrateisCubeManagerInstance extends L2NpcInstance
{

	public L2KrateisCubeManagerInstance(int objectId, L2NpcTemplate template)
	{
		super(objectId, template);
	}

	@Override
	public void onBypassFeedback(L2PcInstance player, String command)
	{
		StringTokenizer st = new StringTokenizer(command, " ");
		String actualCommand = st.nextToken();
		if (command.startsWith("Register"))
		{
			if (player.getInventoryLimit() * 0.8 <= player.getInventory().getSize())
			{
				player.sendPacket(SystemMessageId.INVENTORY_LESS_THAN_80_PERCENT);
				showChatWindow(player, "data/html/krateisCube/32503-9.htm");
				return;
			}

			boolean canParticipate = true;
			int cmdChoice = Integer.parseInt(command.substring(9, 10).trim());
			switch (cmdChoice)
			{
			case 1:
				if (player.getLevel() < 70 || player.getLevel() > 75)
				{
					showChatWindow(player, "data/html/krateisCube/32503-7.htm");
					return;
				}
				break;
			case 2:
				if (player.getLevel() < 76 || player.getLevel() > 79)
				{
					showChatWindow(player, "data/html/krateisCube/32503-7.htm");
					return;
				}
				break;
			case 3:
				if (player.getLevel() < 80)
				{
					showChatWindow(player, "data/html/krateisCube/32503-7.htm");
					return;
				}
				break;
			}

			if (KrateisCubeManager.getInstance().isTimeToRegister())
			{
				if (KrateisCubeManager.getInstance().registerPlayer(player))
				{
					showChatWindow(player, "data/html/krateisCube/32503-4.htm");
					return;
				}
				else
				{
					showChatWindow(player, "data/html/krateisCube/32503-5.htm");
					return;
				}
			}
			else
			{
				showChatWindow(player, "data/html/krateisCube/32503-8.htm");
				return;
			}
			
		}
		else if (command.startsWith("Cancel"))
		{
			KrateisCubeManager.getInstance().removePlayer(player);
			showChatWindow(player, "data/html/krateisCube/32503-6.htm");
			return;
		}
		else if (command.startsWith("TeleportIn"))
		{
			KrateisCubeManager.getInstance().teleportPlayerIn(player);
			return;
		}
		else if (command.startsWith("goto"))
		{
			if (st.countTokens() <= 0)
				return;
			int whereTo = Integer.parseInt(st.nextToken());
			L2TeleportLocation list = TeleportLocationTable.getInstance().getTemplate(whereTo);
			if (list == null || player.isAlikeDead())
				return;
			player.teleToLocation(list.getLocX(), list.getLocY(), list.getLocZ(), true);
			//player.sendPacket(ActionFailed.STATIC_PACKET);
			return;
		}
		else
			super.onBypassFeedback(player,command);
	}

	@Override
	public String getHtmlPath(int npcId, int val)
	{
		String pom = "";

		if (val == 0)
			pom = "" + npcId;
		else
			pom = npcId + "-" + val;

		return "data/html/krateisCube/" + pom + ".htm";
	}
}